local hx__moling = fk.CreateSkill {
  name = "hx__moling",
  tags = { Skill.Compulsory },
}

hx__moling:addEffect(fk.TurnStart, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(hx__moling.name)
  end,
  on_use = function(self, event, target, player, data)
    player.room:addPlayerMark(player, "@hx__moling")
  end,
})

hx__moling:addEffect(fk.Damage, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(hx__moling.name) then
      local damage_events = player.room.logic:getActualDamageEvents(1, function(e)
        return e.data.from == player
      end)
      return #damage_events == 1 and damage_events[1].data == data
    end
end,
  on_use = function(self, event, target, player, data)
    player.room:addPlayerMark(player, "@hx__moling")
  end,
})

hx__moling:addEffect(fk.CardUsing, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(hx__moling.name) and data.card and player:getMark("@hx__moling") ~= 0
  end,
  on_cost = function(self, event, target, player, data)
    if player.room:askToSkillInvoke(player, {
      skill_name = hx__moling.name,
      prompt = "是否令此牌额外结算一次？",
    }) then
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    data.additionalEffect = (data.additionalEffect or 0) + 1
  end,
})

hx__moling:addEffect(fk.TargetConfirming, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(hx__moling.name) and player:getMark("@hx__moling") ~= 0
  end,
  on_cost = function(self, event, target, player, data)
    if player.room:askToSkillInvoke(player, {
      skill_name = hx__moling.name,
      prompt = "是否消耗1点魔灵值令此牌无效？",
    }) then
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:removePlayerMark(player, "@hx__moling")
    data.use.nullifiedTargets = table.simpleClone(player.room.players)
  end,
})

hx__moling:addEffect(fk.TurnEnd, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(hx__moling.name) and player:getMark("@hx__moling") > 1
  end,
  on_cost = function(self, event, target, player, data)
    if player.room:askToSkillInvoke(player, {
      skill_name = hx__moling.name,
      prompt = "是否消耗2点魔灵值执行一个仅有摸牌阶段和出牌阶段的额外回合（此回合内你获得【魔刃】）？",
    }) then
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:removePlayerMark(player, "@hx__moling", 2)
    room:handleAddLoseSkills(player, "hx__moren", nil, true, false)
    room.logic:getCurrentEvent():findParent(GameEvent.Turn):addCleaner(function()
      room:handleAddLoseSkills(player, "-hx__moren")
    end)
    player:gainAnExtraTurn(false ,hx__moling.name,{Player.Draw,Player.Play})
  end,
})




return hx__moling